Ext.define("AM.picker.Image", {

    extend:'Ext.window.Window',


    listeners:{
        render:function () {
            var win = this;
            Ext.Ajax.request({
                url:'GetImgs',

                success:function (response) {
                    var text = response.responseText;
                    var names = text.split('|');
                    var items = []

                    Ext.each(names, function (name) {
                        if (-1 != name.indexOf('.jpg') || -1 != name.indexOf('.gif')) {
                            var image_item = {
                                width:100,
                                height:100,
                                xtype:'image',
                                src:AM.util.URL.image + name,
                                style:{
                                    border:'1px #0687FF solid'
                                },
                                afterRender:function () {
                                    var me = this;
                                    me.el.dom.addEventListener('click', function (e) {
                                        win.doClickItem(name);
                                    })
                                    me.el.dom.addEventListener('dragstart', function (e) {
                                        e.dataTransfer.setData('imgName', name);
                                    });
                                }
                            }

                            win.add(image_item);
                        }


                    })
                }

            })
        },

        beforeclose:function () {
            this.hide();
            return false;
        }
    },

    doClickItem:function (name) {
        AM.service.Insert.insertImgByName(name);
    },


    title:'选择图片',
    autoScroll:true,
    width:500,
    height:300,
    autoShow:true


})